package com.rh.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rh.dto.Page;
import com.rh.entity.po.User;
import com.rh.mapper.UserMapper;
import com.rh.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public void addUser(User user) {
        userMapper.addUser(user);
    }

    @Override
    public List<User> queryUser() {
        return userMapper.queryUser();
    }

    @Override
    public List<User> queryUserByName(String userName) {
        return userMapper.queryUserByName(userName);
    }

    @Override
    public void deleteBatchUser(List<Integer> ids) {
        userMapper.deleteBatchUser(ids);
    }


    @Override
    public void deleteUser(Integer userId) {
        userMapper.deleteUser(userId);
    }

    @Override
    public Page getUserPage(Integer pageNo, Integer pageSize) {
        Page page = new Page();
        PageHelper.startPage(pageNo,pageSize);
        List<User> users = userMapper.queryUser();
        PageInfo<User>info=new PageInfo<>(users);
        page.setPageNo(info.getPageNum());
        page.setPageSize(info.getPageSize());
        page.setHasPre(info.isHasPreviousPage());
        page.setHasNext(info.isHasNextPage());
        page.setPageCount(info.getPages());
        page.setCount(info.getTotal());
        page.setData(info.getList());
        return page;
    }
}
